<?php

defined('MYLITS') ? '' : exit('No direct script access allowed');

/**
 * @version     1.0.0
 * @package     mylits engine
 * @license     GNU General Public License version 3
 * @author      Arfan Fudyartanto D N <arfan@mylits.com> - http://engine.mylits.com
 */
class develHelper {

    public static function copyReplace($originalPath, $copyPath = NULL) {
        $result = true;
        if (!is_dir($copyPath)) {
            $result = mkdir($copyPath, 0644, true);
        }
        if ($handle = opendir($originalPath)) {
            while (false !== ($entry = readdir($handle))) {
                if ($entry != "." && $entry != "..") {
                    if (is_dir($originalPath . $entry)) {
                        $result = self::copyReplace($originalPath . $entry . '/', $copyPath . $entry . '/');
                    } else {
                        $info = pathinfo($originalPath . $entry);
                        if ($info['extension'] = 'txt') {
                            $copyName = str_replace('name', $_POST['name'], str_replace('.txt', '.php', $entry));
                            $content = str_replace('{name}', $_POST['name'], file_get_contents($originalPath . $entry));
                            $fp = fopen($copyPath . '/' . $copyName, 'w');

                            fwrite($fp, $content);
                        }
                    }
                }
            }
        }
        closedir($handle);
    }

}

?>
